<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <link rel="stylesheet" th:href="@{/styles/reset.css}">
    <link rel="stylesheet" th:href="@{/styles/share.css}">
    <link rel="stylesheet" th:href="@{/styles/register.css}">
</head>
<style>

</style>
<body>
<div class="wrap">
     <h1 class="title" th:text="${qrType  == 1} ?'绑定团队':'推荐'"></h1>
     <form id="dataForm">
           <div class="div_form">
                <i class="choose">
                   <input type="radio" class="chooseInput"  id="chooseLabel" value="0" name="roleType">
                   &nbsp;个人类
                </i>
                <i class="choose" th:if="${qrType == 0}">
                   <input type="radio" class="chooseInput" id="chooseLabel1" value="1"  name="roleType">
                   &nbsp;公司类
                </i>
           </div>
           <div class="div_form">
                <span>*</span>
                <input type="text" name="tel" placeholder="请输入手机号">
           </div>
           <span class="msg-box n-right" style="display: none;height:10px;margin-bottom:10px" for="tel"></span>
           <div class="div_form">
                <span>*</span>
                <input type="text" placeholder="请输入验证码" class="yzm" name="captcha">
               	<input type="button" class="btnCode" value="获取验证码" onclick="getCode(this)" />
           </div>
           <span class="msg-box n-right" style="display: none;height:10px;margin-bottom:10px" for="captcha"></span>
           <div class="div_form pass" style="display: none">
                <span>*</span>
                <input type="password" placeholder="密码" name="password" >
                <input type="hidden" id="old_pass" value="">
           </div>
           <span class="msg-box n-right" style="display: none;height:10px;margin-bottom:10px" for="password"></span>
     
           <div class="div_form">
             <span> </span>
             <p th:inline="text" th:if="${qrType == 0}">推荐人手机号码:[[${phone}]]</p>
             <p th:inline="text" th:if="${qrType == 1}">发展人手机号码:[[${phone}]]</p>
           </div>
           <div class="chooseCity">
                <span th:inline="text">[[${@environment.getProperty('up.city') ?: '北京'}]]</span>
           </div>
           <div class="tagLogin">
           	<div class="readCb3">
               <span class="vam">
                     <input id="readCb" name="readafter" value=""  type="checkbox">
               </span>
               <label for="readCb" class="vam1">
                  我已阅读并同意
                 <a href="/agreement/getDetail/优铺用户注册协议" target="_blank">《优铺用户协议》</a>
               </label>
             </div>
               <p th:if="${(leader == null || !leader) && qrType == 1}" style="color:red;margin-top:4px;">您目前绑定的团队不存在!</p>
               
           </div>
           <input type="button" class="btn" value="确 认" />
     </form>
     <p class="tips">
        温馨提示：通过优铺注册的用户，我们不会公开您的姓名及电话等隐私信息，请放心使用
     </p>
</div>
<script type="text/javascript" th:src="@{/scripts/jquery-1.7.2.min.js}"></script>
<script type="text/javascript" th:src="@{/scripts/nv/jquery.validator.js}"></script>
<script type="text/javascript" th:src="@{/scripts/nv/local/zh_CN.js}"></script>
<script type="text/javascript" th:src="@{/scripts/register.js}"></script>
<script th:inline="javascript">
$(function () {
	//validator.mainFun();
	var readCbSelect = $('#readCb').attr('checked');
    $('#readCb').attr('checked') ? $('#readCb').parent().addClass('selected') : $('#readCb').parent().removeClass('selected');
    $('#readCb').change(function () {
        var readCbSelect = $('#readCb').attr('checked');
        if (readCbSelect) {
            $(this).parent().addClass('selected');
        } else {
            $(this).parent().removeClass('selected');
        }
    });
    $("#chooseLabel").click(function () {
        $(this).parent().addClass("choosed").siblings().removeClass("choosed");
    });

	$("#chooseLabel1").click(function () {
	        $(this).parent().addClass("choosed").siblings().removeClass("choosed");
	});
    //赋值默认值
    $('#readCb').click()
    $('.chooseInput').click()
    $("#chooseLabel").click()
    $('.btn').click(function () {
    		var roleType = $('input:radio[name="roleType"]:checked').val();
		var tel = $("input[name=tel]").val()
		var captcha = $("input[name=captcha]").val()
		var password = $("input[name=password]").val()
		var readCbSelect = $('#readCb').attr('checked');
		if(!readCbSelect){
			alert("请阅读优铺用户协议");
			return;
		}
    		if(!roleType){
    			alert("请选择注册类型")
    			return;
    		}
    		if(!tel){
    			alert("请输入手机号")
    			return;
    		}
    		if (!/(^[1][0-9]{10}$)/.test(tel)) {
   		    alert("手机号格式错误")
   		    return;
   		 }
    		if(!captcha){
    			alert("请输入验证码")
    			return;
    		}
    		var old_pass = $("#old_pass").val();
    		if(old_pass=='1' && !password){
    			alert("请输入密码")
    			return;
    		}
    		var params={};
    		params.roleType = $('input:radio[name="roleType"]:checked').val();
    		params.tel = $("input[name=tel]").val()
    		params.password = $("input[name=password]").val()
    		params.captcha = $("input[name=captcha]").val()
		params.qrPhone = [[${phone}]]
    		params.qrType = [[${qrType}]]
     		if (params.qrPhone == tel) {
       		    alert("别调皮，请不要扫描自己哦！")
       		    return;
       		 }
		var city = [[${@environment.getProperty('up.city') ?: '北京'}]]
		if(city == '北京') {
			city = 36
		  } else if(city == '天津') {
			city = 37
		  } else if(city == '海南') {
			city = 38
		  } else if(city == '长沙') {
			city = 39
		  } else if(city == '沈阳') {
			city = 40
		  } else if(city == '商丘') {
			city = 41
		  } else {
		    alert('地区数据错误')
		    return
		  }
    		params.city = city
    		$.post("/user/register",params,function(data,status){
    			if(data.id){
    				alert(data.msg)
    				window.location.href="/view/download.html"
    			}else{
    				alert(data.msg)
    			}
    		})
	})
	
});
	
	function getCode(obj){
		var phone = $("input[name=tel]").val()
		var qrPhone = [[${phone}]]
    		var qrType = [[${qrType}]]
		if(!phone){
			alert("请输入手机号")
			return
		}
		if (!/(^[1][0-9]{10}$)/.test(phone)) {
   		    alert("手机号格式错误")
   		    return;
   		 }
		
		$.get("/user/registerSendMessage?phone="+phone+"&qrPhone="+qrPhone+"&qrType="+qrType,function(data,status){
			if(data.id == 2){
				alert(data.msg)
				$(".pass").show();
				$("#old_pass").val("1");
			}else if(data.id == 1){
				alert(data.msg)
				$(".pass").hide();
				$("#old_pass").val("");
			}else{
				alert(data.msg)
			}
		})
		settime(obj);
	}
	
	var countdown=60; 
	function settime(obj){
		if (countdown == 0) { 
			obj.removeAttribute("disabled"); 
			obj.value="获取验证码"; 
			countdown = 60; 
			return;
		} else { 
			obj.setAttribute("disabled", true); 
			obj.value="获取验证码(" + countdown + ")"; 
			countdown--; 
		} 
		setTimeout(function() {settime(obj) },1000) 
	}

</script>
</body>
</html>
